package com.mkvld.appietijdenv2.data;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class Preferences {
	public static SharedPreferences get(Context context) {
		return PreferenceManager.getDefaultSharedPreferences(context);
	}
	public static int getContract(Context context) {
		return Integer.parseInt(get(context).getString("pref_contract", "0"));
	}
	public static double getLoan(Context context) {
		return Double.parseDouble(get(context).getString("pref_loan", "0.00"));
	}
	public static int getSetBudgetPeriod(Context context) {
		return Integer.parseInt(get(context).getString("budget_period", "-2"));
	}
	public static int getSetBudgetYear(Context context) {
		return Integer.parseInt(get(context).getString("budget_year", "-1"));
	}
	public static boolean isNotificationEnabled(Context context) {
		return Boolean.parseBoolean(get(context).getString("pref_payday_notification", "true"));
	}
	public static PeriodBudgetOld getBudget(Context context) {
		SharedPreferences prefs = get(context);
		return new PeriodBudgetOld(
				new Budget(
						Budget.TYPE_VACATION, 
						Double.parseDouble(prefs.getString("budget_vacation_budget", "0")), 
						Double.parseDouble(prefs.getString("budget_vacation_breeded", "0")), 
						Double.parseDouble(prefs.getString("budget_vacation_withdrawn", "0")), 
						Double.parseDouble(prefs.getString("budget_vacation_nextyear", "0"))), 
				new Budget(
						Budget.TYPE_ADV, 
						Double.parseDouble(prefs.getString("budget_adv_budget", "0")), 
						Double.parseDouble(prefs.getString("budget_adv_breeded", "0")), 
						Double.parseDouble(prefs.getString("budget_adv_withdrawn", "0")), 
						0), 
				new Budget(
						Budget.TYPE_TVT, 
						Double.parseDouble(prefs.getString("budget_tvt_budget", "0")), 
						Double.parseDouble(prefs.getString("budget_tvt_breeded", "0")), 
						Double.parseDouble(prefs.getString("budget_tvt_withdrawn", "0")), 
						0), 
				Integer.parseInt(prefs.getString("budget_period", "0")) - 1, 
				Integer.parseInt(prefs.getString("budget_year", "0")));
	}
	public static int getNotificationId(Context context) {
		SharedPreferences prefs = get(context);
		int id = prefs.getInt("notificationId", 0);
		prefs.edit().putInt("notificationId", id + 1).apply();
		return id;
	}
	public static int getCloudId(Context context) {
		return get(context).getInt("cloud_id", -1);
	}
	
	public static void setCloudId(Context context, int cloudId) {
		get(context).edit().putInt("cloud_id", cloudId).commit();
	}
	public static boolean getPushEnabled(Context context) {
		return get(context).getBoolean("pref_payday", false);
	}
	public static void setContract(Context context, int contract) {
		get(context).edit().putString("pref_contract", Integer.toString(contract)).commit();
	}
	public static void setLoan(Context context, double loan) {
		get(context).edit().putString("pref_loan", Double.toString(loan)).commit();
	}
	public static void setPush(Context context, int push) {
		get(context).edit().putBoolean("pref_payday", push == 1).commit();
	}
}
